#include "../mqserver/queue.hpp"
#include <gtest/gtest.h>

MsgQueueManager::ptr qmp;

class QueueTest : public testing::Environment {
public:
    virtual void SetUp() override {
        qmp = std::make_shared<MsgQueueManager>("./data/meta.db");
    }
    virtual void TearDown() override {
        //qmp->clear();
    }
};

TEST(QueueTest, insert_test){
    std::unordered_map<std::string, std::string> map = {{"k1", "v1"}};
    qmp->declareQueue("queue1", true, false, false, map);
    qmp->declareQueue("queue2", true, false, false, map);
    qmp->declareQueue("queue3", true, false, false, map);
    qmp->declareQueue("queue4", true, false, false, map);
    ASSERT_EQ(qmp->size(), 4);
}

TEST(QueueTest, select_test){
    MsgQueue::ptr mqp = qmp->selectQueue("queue3");
    ASSERT_EQ(mqp->name, "queue3");
    ASSERT_EQ(mqp->durable, true);
    ASSERT_EQ(mqp->exclusive, false);
    ASSERT_EQ(mqp->auto_delete, false);
    ASSERT_EQ(mqp->getArgs(), std::string("k1=v1&"));
}


TEST(QueueTest, remove_test){
    qmp->deleteQueue("queue3");
    MsgQueue::ptr mqp = qmp->selectQueue("queue3");
    ASSERT_EQ(mqp.get(), nullptr);
    ASSERT_EQ(qmp->exists("queue3"), false);
}


int main(int argc, char* argv[]){
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new QueueTest);
    RUN_ALL_TESTS();
    return 0;
}